#include "Cmusic.h"

Cmusic::Cmusic(std::string name)
{
music=Mix_LoadMUS(name.c_str());
}


Cmusic::~Cmusic()
{
Mix_FreeMusic(music);
}


void Cmusic::play()
{

	if(Mix_PlayingMusic()==0)
	{
		Mix_PlayMusic(music,-1);

	}
	else
	{
		if(Mix_PausedMusic()==1) Mix_ResumeMusic();

	}
}




void Cmusic::pause()
{

	if(Mix_PlayingMusic()==1)Mix_PauseMusic();


}




void Cmusic::reset()
{

	Mix_HaltMusic();
}


void Cmusic::volumeup()
{
	int current=Mix_VolumeMusic(-1)+2;
	if(current>128)current=128;
	Mix_VolumeMusic(current);


}
void Cmusic::volumedown()
{
	int current=Mix_VolumeMusic(-1)-2;
	if(current<0)current=0;
	Mix_VolumeMusic(current);


}

void Cmusic::setvolume(int percentage)
{

	int volume=128*percentage/100;
	Mix_VolumeMusic(volume);





}